using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.DataAccess.Common
{
    /// <summary>
    /// 枚举类型转换工具
    /// </summary>
    public class EnumTools
    {
        public static T Convert<T>(string value)
        {
            Type t = typeof(T);
            if (!t.IsEnum)
                throw new FasException(DataAccessErrorCode.DataType.TypeCastError, string.Format(CommonStringClassCommon.EnumTools_Convert,t));
            if (string.IsNullOrEmpty(value))
                throw new FasException(DataAccessErrorCode.DataType.NullValue, string.Format(CommonStringClassCommon.EnumTools_Convert1));
            return (T)Enum.Parse(t, value);
        }
    }
}
